package com.ruoyi.web.controller.commodity;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.qrcodeUtils.QRCodeGenerator;
import com.ruoyi.web.qrcodeUtils.vo.ImagePathsVo;
import com.ruoyi.web.qrcodeUtils.vo.QRVo;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
public class QRCodeGeneratorController {

    @Resource
    QRCodeGenerator qrCodeGenerator;

    /**
     * 批量生成二维码
     *
     * @return
     */
    @PostMapping("/QRCodeGenerator")
    public AjaxResult generateQRCode(@RequestBody List<QRVo> qrVoList) {
        return AjaxResult.success(null, qrCodeGenerator.bactha(qrVoList));
    }

    /**
     * 下载
     * @param pathsVo
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/downloadQRCode")
    public ResponseEntity<FileSystemResource> downloadQRCode(@RequestBody ImagePathsVo pathsVo, HttpServletResponse response) throws IOException {
        return qrCodeGenerator.downloadQRCode(pathsVo.getImagePaths(), response);
    }
}
